package com.distribute.framework.model;

import com.distribute.framework.core.web.helper.Utils;
import java.lang.reflect.Field;
import java.util.Date; 
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import javax.annotation.Resource;

import com.distribute.framework.core.web.util.Page;
import com.distribute.framework.core.lang.*; 
import com.distribute.framework.core.web.helper.WebHelper.LzMap;
import com.distribute.framework.core.util.Function;
import com.distribute.framework.core.util.IbatisMap;
import com.distribute.framework.config.*;
import com.distribute.framework.plugin.*;

@namespace("products/redpacket")
public @caption("派发红包") @database(DatabaseNames.distribute_sys) @source("distribute_sys") @table("red_packet") class RedPacket implements java.io.Serializable
{
	private static final long serialVersionUID = 1l;
		
	
		
	private @caption("编号") @column("id")    @primary  @notnull  @note("  ") Long id;// 主键 非空     
			
 			
 			
 		
	
		
	private @caption("品牌信息") @column("merchant")     @notnull  @relate("$merchant") @RelateClass(Merchant.class)  @note("  ") Long merchant;// 非空     
			
 	private transient Merchant $merchant;//关联对象[品牌信息]
 			
 			
 			
 		
	
		
	private transient @caption("用户编号") @column("uid")    @primary  @notnull  @note("  ") Long uid;// 主键 非空     
			
 			
 			
 		
	
		
	private @caption("发红包人") @column("red_enveloper")     @notnull  @relate("$redEnveloper") @RelateClass(Member.class)  @note("  ") Long redEnveloper;// 非空     
			
 	private transient Member $redEnveloper;//关联对象[会员信息]
 			
 			
 			
 		
	
		
	private @caption("红包数量") @column("quantity")     @notnull  @note("  ") Integer quantity;// 非空     
			
 			
 			
 		
	
		
	private @caption("余额产品") @column("product")     @notnull  @relate("$product") @RelateClass(Product.class)  @note("  ") Long product;// 非空     
			
 	private transient Product $product;//关联对象[产品余额]
 			
 			
 			
 		
	
		
	private @caption("红包类型") @column("types")     @notnull  @note(" 1:单人红包 2:多人红包  ") Short types;// 非空 1:单人红包 2:多人红包     
			
 			
 			
 		
	
		
	private @caption("默认有效期") @column("validity")     @notnull  @note("  ") Date validity;// 非空     
			
 			
 			
 		
	
		
	private @caption("已领取人数") @column("recipients")      @note("  ") Integer recipients;//     
			
 			
 			
 		
	
		
	private @caption("唯一标识") @column("unique")      @note("  ") String unique;//     
			
 			
 			
 		
	
		
	private @caption("修改时间") @column("update_time")     @notnull  @note("  ") Date updateTime;// 非空     
			
 			
 			
 		
	
		
	private @caption("发放时间") @column("add_time")     @notnull  @note("  ") Date addTime;// 非空     
			
 			
 			
 		
	
		
	private @caption("状态") @column("status")     @notnull  @note(" 1:有效中 0:已失效  ") Short status;// 非空 1:有效中 0:已失效     
			
 			
 			
 		
	
	 
	//默认构造函数
	public RedPacket(){ 
	
	}
	
	//主键构造函数
	public RedPacket(Long id){
		this.id = id;
	}
	
	/**所有字段构造函数 
	 RedPacket(
	 	Utils.getLong("merchant")//品牌信息 [非空]
	 	,Utils.getLong("redEnveloper")//发红包人 [非空]
	 	,Utils.getInteger("quantity")//红包数量 [非空]
	 	,Utils.getLong("product")//余额产品 [非空]
	 	,Utils.getShort("types")//红包类型 [非空]
	 	,Utils.getDate("validity")//默认有效期 [非空]
	 	,Utils.getInteger("recipients")//已领取人数
	 	,Utils.getString("unique")//唯一标识
	 	,Utils.getDate("updateTime")//修改时间 [非空]
	 	,Utils.getDate("addTime")//发放时间 [非空]
	 	,Utils.getShort("status")//状态 [非空]
	 )
	**/
	public RedPacket(Long merchant,Long redEnveloper,Integer quantity,Long product,Short types,Date validity,Integer recipients,String unique,Date updateTime,Date addTime,Short status){
		
			
			
		this.merchant=merchant;
		
			
			
		this.redEnveloper=redEnveloper;
		
			
		this.quantity=quantity;
		
			
		this.product=product;
		
			
		this.types=types;
		
			
		this.validity=validity;
		
			
		this.recipients=recipients;
		
			
		this.unique=unique;
		
			
		this.updateTime=updateTime;
		
			
		this.addTime=addTime;
		
			
		this.status=status;
		
	}
	
	//设置非空字段
	public RedPacket setNotNull(Long merchant,Long redEnveloper,Integer quantity,Long product,Short types,Date validity,Date updateTime,Date addTime,Short status){
		
			
			
		this.merchant=merchant;
		
			
			
		this.redEnveloper=redEnveloper;
		
			
		this.quantity=quantity;
		
			
		this.product=product;
		
			
		this.types=types;
		
			
		this.validity=validity;
		
			
			
			
		this.updateTime=updateTime;
		
			
		this.addTime=addTime;
		
			
		this.status=status;
		
		return this;
	}
	
	
		
	/** 编号 [非空]       **/
	public RedPacket id(Long id){
		this.id = id;
		this.setSeted(F.id);
		return this;
	}
	
		
	/** 品牌信息 [非空] [Merchant]      **/
	public RedPacket merchant(Long merchant){
		this.merchant = merchant;
		this.setSeted(F.merchant);
		return this;
	}
	
		
		
	/** 发红包人 [非空] [Member]      **/
	public RedPacket redEnveloper(Long redEnveloper){
		this.redEnveloper = redEnveloper;
		this.setSeted(F.redEnveloper);
		return this;
	}
	
		
	/** 红包数量 [非空]       **/
	public RedPacket quantity(Integer quantity){
		this.quantity = quantity;
		this.setSeted(F.quantity);
		return this;
	}
	
		
	/** 余额产品 [非空] [Product]      **/
	public RedPacket product(Long product){
		this.product = product;
		this.setSeted(F.product);
		return this;
	}
	
		
	/** 红包类型 [非空]   1:单人红包 2:多人红包     **/
	public RedPacket types(Short types){
		this.types = types;
		this.setSeted(F.types);
		return this;
	}
	
		
	/** 默认有效期 [非空]       **/
	public RedPacket validity(Date validity){
		this.validity = validity;
		this.setSeted(F.validity);
		return this;
	}
	
		
	/** 已领取人数        **/
	public RedPacket recipients(Integer recipients){
		this.recipients = recipients;
		this.setSeted(F.recipients);
		return this;
	}
	
		
	/** 唯一标识        **/
	public RedPacket unique(String unique){
		this.unique = unique;
		this.setSeted(F.unique);
		return this;
	}
	
		
	/** 修改时间 [非空]       **/
	public RedPacket updateTime(Date updateTime){
		this.updateTime = updateTime;
		this.setSeted(F.updateTime);
		return this;
	}
	
		
	/** 发放时间 [非空]       **/
	public RedPacket addTime(Date addTime){
		this.addTime = addTime;
		this.setSeted(F.addTime);
		return this;
	}
	
		
	/** 状态 [非空]   1:有效中 0:已失效     **/
	public RedPacket status(Short status){
		this.status = status;
		this.setSeted(F.status);
		return this;
	}
	
	
	
	/**
	* 克隆对象
	**/
	public RedPacket clone(){
		RedPacket clone = new RedPacket();
		
			
			
		clone.merchant=this.merchant;
		
			
			
		clone.redEnveloper=this.redEnveloper;
		
			
		clone.quantity=this.quantity;
		
			
		clone.product=this.product;
		
			
		clone.types=this.types;
		
			
		clone.validity=this.validity;
		
			
		clone.recipients=this.recipients;
		
			
		clone.unique=this.unique;
		
			
		clone.updateTime=this.updateTime;
		
			
		clone.addTime=this.addTime;
		
			
		clone.status=this.status;
		
		return clone;
	}
	
	
	
	
	
	/**
	 * 根据ID取派发红包
	 * @param id
	 * @return
	 */
	public static @api RedPacket get(Long id){		
		return getRedPacketById(id);
	}
	
	
	
	/**
	 * 获取所有派发红包
	 * @return
	 */
	public static @api List<RedPacket> list(Map params,Integer size){
		return getRedPacketList(params,size);
	}
	/**
	 * 获取派发红包分页
	 * @return
	 */
	public static @api Page<RedPacket> page(Integer page,Integer size,Map params){
		return getRedPacketPage(page, size , params);
	}
	
	
	/**
	 * 根据查询条件取派发红包
	 * @param params
	 * @return
	 */
	public static @api RedPacket Get(Map params){
		return getRedPacket(params);
	}
	/**
	 * 获取派发红包数
	 * @return
	 */
	public static @api Long count(Map params){
		return getRedPacketCount(params);
	}
	/**
	 * 获取派发红包数
	 * @return
	 */
	public static @api <T> T eval(String eval,Map params){
		return getRedPacketEval(eval,params);
	}
	
	
	/**
	 * 获取派发红包图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey){
		return getRedPacketStats(params,sumKey,groupKey,-1);
	}
	/**
	 * 获取派发红包图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey,int dateType){
		return getRedPacketStats(params,sumKey,groupKey,dateType);
	}
	
	
	/**
	 * 根据ID取派发红包
	 * @param id
	 * @return
	 */
	public static @api RedPacket getRedPacketById(Long id){		
		return getRedPacketDao().getRedPacketById(id);
	}
	
	
	
	
	/**
	 * 根据ID取派发红包的标识键值
	 * @param id
	 * @return
	 */
	public static @api String getKeyValue(Object key){
		Long id = Utils.parseLong(key);	
		if(id==null || id.longValue()==0 ){
			
			return null;
			
		}
		String value = null;
				
		if(value==null){
			RedPacket redPacket = get(id);
			if(redPacket!=null){
				String strValue = redPacket.getId$();
				
				if(!"Id".equals("Id"))
					strValue+="("+redPacket.getId$()+")";
				
				
				value = strValue;
			}else{
				
				value = "{"+id+"}";
			}
		}
		
		/************LAZY3Q_ID_KEYVALUE************/
		/************LAZY3Q_ID_KEYVALUE************/
		return value;
	}	
	
	
	/**
	 * 获取当前对象的键值
	 * @return
	 */
	public String getKeyValue(){
		
		/************LAZY3Q_CODE_KEYVALUE************/
		/************LAZY3Q_CODE_KEYVALUE************/
		String keyValue = this.getId$();
		
		if(!"Id".equals("Id"))
			keyValue+="("+this.getId$()+")";
		
		return keyValue;
	}
	
	
	/**
	 * 根据关键字精确查询派发红包对象
	 * @return
	 */
	public static @api RedPacket find(String key){
		if(Utils.empty(key))return null;
		Map params = new HashMap();
		if(key.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
			params.put("id", key.toLowerCase().replaceFirst("id:", ""));					
		else{//按标识查询，精确查询
			String strDefinex = "";
			
			strDefinex+=" or id = '"+key.replaceAll("'", "''")+"'";
			
			strDefinex="(2=1 "+strDefinex+")";
			params.put("definex",strDefinex);
		}
		
		/************LAZY3Q_CODE_FIND************/
		/************LAZY3Q_CODE_FIND************/
		return RedPacket.getRedPacket(params);
	}
	
	
	/**
	 * 根据关键字查询派发红包
	 * @return
	 */
	public static @api List<Map> query(String key,int size,Map params,Boolean bObject){
		if(Utils.empty((String)params.get("asc")) && Utils.empty((String)params.get("desc")))//如果未传入排序字段
			params.put("desc","id");//那么，默认以主键降序，传给Dao层
		String strTerm=key;		
		if(!Utils.empty(strTerm)){
			if(strTerm.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
				params.put("id", strTerm.toLowerCase().replaceFirst("id:", ""));					
			else//按标识查询，模糊查询请带%
			{
				String strDefinex = "";
				
				strDefinex+=" or id like '%"+strTerm.replaceAll("'", "''")+"%'";
				
				strDefinex="(2=1 "+strDefinex+")";
				params.put("definex",strDefinex);
			}
		}
		
		
		/************LAZY3Q_CODE_QUERY************/
		/************LAZY3Q_CODE_QUERY************/
			
		List<RedPacket> list = page(0,size,params).getResult();
		
		/**
		* OK!取到数据拼成放入Map中，[{value,text,object:{...}},...]
		* value:数据ID，text:数据标识,object,整个对象
		**/
		List<Map> result = new java.util.ArrayList();
		for(RedPacket redPacket:list){
			Map map = new HashMap();
			map.put("key",redPacket.getId().toString());
			map.put("value", Utils.js(redPacket.getKeyValue()));
			if(bObject==true)
				map.put("object",redPacket);
			result.add(map);
		}
		
		
		/************LAZY3Q_AFTER_QUERY************/
		/************LAZY3Q_AFTER_QUERY************/
		
		return result;
	}
	
	
	
	/**
	 * 获取所有派发红包
	 * @return
	 */
	public static @api List<RedPacket> getRedPacketList(Map params,Integer size){
		return getRedPacketDao().getRedPacketList(params,0,size);
	}
	
	/**
	 * 获取派发红包分页
	 * @return
	 */
	public static @api Page<RedPacket> getRedPacketPage(Integer page,Integer size,Map params){
		if(page==null)page=0;
		if(size==null)size=20;
		return getRedPacketDao().getRedPacketPage(page, size , params);
	}
	
	/**
	 * 根据查询条件取派发红包
	 * @param params
	 * @return
	 */
	public static @api RedPacket getRedPacket(Map params){
		return getRedPacketDao().getRedPacket(params);
	}
	
	/**
	 * 保存一个派发红包
	 * @param redPacket
	 * @return
	 */
	public static @api RedPacket saveRedPacket(RedPacket redPacket){
		return getRedPacketDao().saveRedPacket(redPacket);
	}
	
	/**
	 * 根据条件更新派发红包
	 * @param values
	 * @param params
	 */
	public static @api int updateRedPacketByConfirm(Map values, Map params){
		return getRedPacketDao().updateRedPacketByConfirm(values,params);
	}
	
	/**
	 * 修改一个派发红包
	 * @param redPacket
	 * @return
	 */
	public static @api int updateRedPacket(RedPacket redPacket){
		return getRedPacketDao().updateRedPacket(redPacket);
	}
	
	/**
	 * 更新派发红包非空字段
	 * @param redPacket
	 */
	public static @api int updateRedPacket$NotNull(RedPacket redPacket){
		return getRedPacketDao().updateRedPacket$NotNull(redPacket);
	}
	
	/**
	 * 获取派发红包数
	 * @return
	 */
	public static @api Long getRedPacketCount(Map params){
		return getRedPacketDao().getRedPacketCount(params);
	}
		
		
	/**
	 * 获取派发红包自定义求和表达式,比如求和:eval="sum(id)"
	 * @return
	 */	
	public static @api <T> T getRedPacketEval(String eval,Map params){
		return getRedPacketDao().getRedPacketEval(eval,params);
	}
	
	
	/**
	 * 获取派发红包图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> getRedPacketStats(Map params,C sumKey,C groupKey,int dateType){
		//TODO:图表统计功能未实现
		
		Map<String,Object> groups=new HashMap();//要分组的字段
		Map<String,Object> sums=new HashMap();//要统计的字段
		
		String[][] dateFormats=new String[][]{
				null,
				new String[]{"%Y","yyyy年","Y"},
				new String[]{"%Y-%m","yyyy年MM月","M"},
				new String[]{"%Y%U","yyyy年第ww周","W"},
				new String[]{"%Y-%m-%d","yyyy年MM月dd日","D"},
				new String[]{"%Y-%m-%d %H","yyyy年MM月dd日 HH点","H"},
				new String[]{"%m","MM月"},
				new String[]{"%d","dd号"},
				new String[]{"%H","HH点"} 
		};
		
		//获取要分组的字段，放入Map中
		if(dateType>0){
			groups.put(groupKey.toString(),"DATE_FORMAT({key},'"+dateFormats[dateType][0]+"')");
		}else{
			groups.put(groupKey.toString(),"{key}");
		}
		if(dateType<6 && dateType>0){ 
			params.put("asc", groupKey.toString()); 
			if(params.get(groupKey.name()+"Start")==null){
				params.put(groupKey.name()+"Start", Utils.date(new Date(), -24, dateFormats[dateType][2]));
			}
		}
		
		
		//获取要统计的字段，放入Map中
		if(sumKey.toString().equals("count")){
			sums.put(sumKey.toString(),"count(*)");
		}else{
			sums.put(sumKey.toString(),"sum({key})");
		}
		
		List<Map> list = getRedPacketDao().getRedPacketStats(params,groups,sums);
		
		List<Map> result = new ArrayList();
		for(Map m:list){
			Map map = new HashMap();
			Object value = m.get(sumKey.toString());
			Object name = null;
			Object groupValue = m.get(groupKey.toString());
			if(dateType>0){
				name = Utils.date(Utils.parseDate(groupValue), dateFormats[dateType][1]);
			}else{
				try{
					java.lang.reflect.Method method = RedPacket.class.getMethod("get"+Utils.ForMat(groupKey.toString())+"$");
					method.setAccessible(true);
					name = method.invoke(RedPacket.fromMap(m));
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
			map.put("name", name);
			map.put("value", value);
			result.add(map);
		}
		return result;
	}
	
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static int updateRedPacket(Map set,Map where){
		if(set.isEmpty())throw new RuntimeException("set为空");
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		return getRedPacketDao().updateRedPacketByConfirm(set, where);
	}
	
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void deleteRedPacket(Map where){
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		getRedPacketDao().deleteRedPacketByConfirm(where);
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void delete(Long id){
		if(id==null)throw new RuntimeException("id为空");
		
		getRedPacketDao().removeRedPacketById(id);
		
	}
	
	
	/**
	 * 保存派发红包对象
	 * @param params
	 * @return
	 */
	public RedPacket save(){
		if(this.getId()!=null)
			getRedPacketDao().updateRedPacket(this);
		else
			return getRedPacketDao().saveRedPacket(this);
		return this;
	}
	
	
	/**
	 * 更新派发红包对象的非空字段,注意跟Service里面的update不一样哦
	 * @param params
	 * @return
	 */
	public int update(){
		return getRedPacketDao().updateRedPacket$NotNull(this);
	}
	
	
	/**
	 * 删除
	 * @param params
	 * @return
	 */
	public void delete(){
		
		if(Utils.equals(Utils.config("logic_delete"),"true"))
			getRedPacketDao().removeRedPacketById(this.getId());
		else
		
			getRedPacketDao().deleteRedPacketById(this.getId());
	}
	
	/**
	 * 执行事务
	 * @param function
	 */
	public static <T> T execute(Function function){
		return getRedPacketDao().executeTransaction(function);
	}

	
	
	/*******************************编号**********************************/	
	/**
	* 编号 [非空]      
	**/
	public Long getId(){
		
		if(this.id!=null){
			return this.id;
		}
		
		return this.id;
	}
	/**
	* 获取编号格式化(toString)
	**/
	public String getId$(){
		String strValue="";
	
	
		 strValue=Utils.string(this.getId());
	 
	 	 return strValue;
	}
	/**
	* 根据编号反格式化
	**/
	public void setId$(String strValue){
		if(Utils.empty(strValue)){
			this.id=null;
			return;
		}
	
	
	 	this.id=Utils.parseLong(strValue);
	 
	}
	
	/**
	* 编号 [非空]      
	**/
	public void setId(Long id){
		this.id = id;
		
		this.setSeted(F.id);
		
	}
	
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 	
 	
	
	
	/*******************************品牌信息**********************************/	
	/**
	* 品牌信息 [非空] [Merchant]     
	**/
	public Long getMerchant(){
		
		if(this.merchant!=null){
			return this.merchant;
		}
		
		return this.merchant;
	}
	/**
	* 获取品牌信息格式化(toString)
	**/
	public String getMerchant$(){
		String strValue="";
	
	
		 
		if(this.getMerchant()!=null){
			
				strValue+=Utils.string(Merchant.getKeyValue(this.getMerchant()));
			
		}			
		 
	 
	 	 return strValue;
	}
	/**
	* 根据品牌信息反格式化
	**/
	public void setMerchant$(String strValue){
		if(Utils.empty(strValue)){
			this.merchant=null;
			return;
		}
	
	
		 
		Merchant item = Merchant.find(strValue);
		if(item!=null){
			
			this.merchant = Utils.parseLong(item.getId());
			
		}
		 
	 
	}
	
	/**
	* 品牌信息 [非空] [Merchant]     
	**/
	public void setMerchant(Long merchant){
		this.merchant = merchant;
		
		this.setSeted(F.merchant);
		
	}
	
	
		 
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 		
	/**
	* 获取关联对象[品牌信息]
	**/	 			
 	public Merchant get$merchant(){
 		if(this.$merchant!=null)
 			return this.$merchant;
 		com.distribute.framework.model.Merchant merchant = null;
		if(this.getMerchant()!=null){
		
 			merchant = Merchant.get(this.getMerchant());
 		
 		}
 		return merchant;
	}
	
 	
	
	
	/*******************************用户编号**********************************/	
	/**
	* 用户编号 [非空]      
	**/
	public Long getUid(){
		
		if(this.uid!=null){
			return this.uid;
		}
		
		Member member = Member.get(this.getRedEnveloper());
		if(member!=null){
			this.uid=member.getUid();
		}
				
		
		return this.uid;
	}
	/**
	* 获取用户编号格式化(toString)
	**/
	public String getUid$(){
		String strValue="";
	
	
		 strValue=Utils.string(this.getUid());
	 
	 	 return strValue;
	}
	/**
	* 根据用户编号反格式化
	**/
	public void setUid$(String strValue){
		if(Utils.empty(strValue)){
			this.uid=null;
			return;
		}
	
	
	 	this.uid=Utils.parseLong(strValue);
	 
	}
	
	/**
	* 用户编号 [非空]      
	**/
	public void setUid(Long uid){
		this.uid = uid;
		
	}
	
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 	
 	
	
	
	/*******************************发红包人**********************************/	
	/**
	* 发红包人 [非空] [Member]     
	**/
	public Long getRedEnveloper(){
		
		if(this.redEnveloper!=null){
			return this.redEnveloper;
		}
		
		return this.redEnveloper;
	}
	/**
	* 获取发红包人格式化(toString)
	**/
	public String getRedEnveloper$(){
		String strValue="";
	
	
		 
		if(this.getRedEnveloper()!=null){
			
				strValue+=Utils.string(Member.getKeyValue(this.getRedEnveloper()));
			
		}			
		 
	 
	 	 return strValue;
	}
	/**
	* 根据发红包人反格式化
	**/
	public void setRedEnveloper$(String strValue){
		if(Utils.empty(strValue)){
			this.redEnveloper=null;
			return;
		}
	
	
		 
		Member item = Member.find(strValue);
		if(item!=null){
			
			this.redEnveloper = Utils.parseLong(item.getUid());
			
		}
		 
	 
	}
	
	/**
	* 发红包人 [非空] [Member]     
	**/
	public void setRedEnveloper(Long redEnveloper){
		this.redEnveloper = redEnveloper;
		
		this.setSeted(F.redEnveloper);
		
	}
	
	
		 
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 		
	/**
	* 获取关联对象[会员信息]
	**/	 			
 	public Member get$redEnveloper(){
 		if(this.$redEnveloper!=null)
 			return this.$redEnveloper;
 		com.distribute.framework.model.Member member = null;
		if(this.getRedEnveloper()!=null){
		
 			member = Member.get(this.getRedEnveloper());
 		
 		}
 		return member;
	}
	
 	
	
	
	/*******************************红包数量**********************************/	
	/**
	* 红包数量 [非空]      
	**/
	public Integer getQuantity(){
		
		if(this.quantity!=null){
			return this.quantity;
		}
		
		return this.quantity;
	}
	/**
	* 获取红包数量格式化(toString)
	**/
	public String getQuantity$(){
		String strValue="";
	
	
		 strValue=Utils.string(this.getQuantity());
	 
	 	 return strValue;
	}
	/**
	* 根据红包数量反格式化
	**/
	public void setQuantity$(String strValue){
		if(Utils.empty(strValue)){
			this.quantity=null;
			return;
		}
	
	
	 	this.quantity=Utils.parseInteger(strValue);
	 
	}
	
	/**
	* 红包数量 [非空]      
	**/
	public void setQuantity(Integer quantity){
		this.quantity = quantity;
		
		this.setSeted(F.quantity);
		
	}
	
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 	
 	
	
	
	/*******************************余额产品**********************************/	
	/**
	* 余额产品 [非空] [Product]     
	**/
	public Long getProduct(){
		
		if(this.product!=null){
			return this.product;
		}
		
		return this.product;
	}
	/**
	* 获取余额产品格式化(toString)
	**/
	public String getProduct$(){
		String strValue="";
	
	
		 
		if(this.getProduct()!=null){
			
				strValue+=Utils.string(Product.getKeyValue(this.getProduct()));
			
		}			
		 
	 
	 	 return strValue;
	}
	/**
	* 根据余额产品反格式化
	**/
	public void setProduct$(String strValue){
		if(Utils.empty(strValue)){
			this.product=null;
			return;
		}
	
	
		 
		Product item = Product.find(strValue);
		if(item!=null){
			
			this.product = Utils.parseLong(item.getId());
			
		}
		 
	 
	}
	
	/**
	* 余额产品 [非空] [Product]     
	**/
	public void setProduct(Long product){
		this.product = product;
		
		this.setSeted(F.product);
		
	}
	
	
		 
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 		
	/**
	* 获取关联对象[产品余额]
	**/	 			
 	public Product get$product(){
 		if(this.$product!=null)
 			return this.$product;
 		com.distribute.framework.model.Product product = null;
		if(this.getProduct()!=null){
		
 			product = Product.get(this.getProduct());
 		
 		}
 		return product;
	}
	
 	
	
	
	/*******************************红包类型**********************************/	
	/**
	* 红包类型 [非空]   1:单人红包 2:多人红包    
	**/
	public Short getTypes(){
		
		if(this.types!=null){
			return this.types;
		}
		
		return this.types;
	}
	/**
	* 获取红包类型格式化(toString)
	**/
	public String getTypes$(){
		String strValue="";
	
	
		
			
		 if(Utils.equals(Utils.string(this.getTypes()),"1"))
			strValue=Utils.string("单人红包");		 
			
		 if(Utils.equals(Utils.string(this.getTypes()),"2"))
			strValue=Utils.string("多人红包");		 
			
		
	 
	 	 return strValue;
	}
	/**
	* 根据红包类型反格式化
	**/
	public void setTypes$(String strValue){
		if(Utils.empty(strValue)){
			this.types=null;
			return;
		}
	
	
		
			
		 if(Utils.equals(strValue,"单人红包"))
		 	this.types=Utils.parseShort("1");
			
		 if(Utils.equals(strValue,"多人红包"))
		 	this.types=Utils.parseShort("2");
			
		
	 
	}
	
	/**
	* 红包类型 [非空]   1:单人红包 2:多人红包    
	**/
	public void setTypes(Short types){
		this.types = types;
		
		this.setSeted(F.types);
		
	}
	
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 	
 	
	
	
	/*******************************默认有效期**********************************/	
	/**
	* 默认有效期 [非空]      
	**/
	public Date getValidity(){
		
		if(this.validity!=null){
			return this.validity;
		}
		
		return this.validity;
	}
	/**
	* 获取默认有效期格式化(toString)
	**/
	public String getValidity$(){
		String strValue="";
	
	
	 	
		 strValue=Utils.string(Utils.date(this.getValidity(),"yyyy-MM-dd HH:mm:ss"));
		
	 
	 	 return strValue;
	}
	/**
	* 根据默认有效期反格式化
	**/
	public void setValidity$(String strValue){
		if(Utils.empty(strValue)){
			this.validity=null;
			return;
		}
	
	
	 	this.validity=Utils.date(strValue,"yyyy-MM-dd HH:mm:ss");
	 
	}
	
	/**
	* 默认有效期 [非空]      
	**/
	public void setValidity(Date validity){
		this.validity = validity;
		
		this.setSeted(F.validity);
		
	}
	
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 	
 	
	
	
	/*******************************已领取人数**********************************/	
	/**
	* 已领取人数       
	**/
	public Integer getRecipients(){
		
		if(this.recipients!=null){
			return this.recipients;
		}
		
		return this.recipients;
	}
	/**
	* 获取已领取人数格式化(toString)
	**/
	public String getRecipients$(){
		String strValue="";
	
	
		 strValue=Utils.string(this.getRecipients());
	 
	 	 return strValue;
	}
	/**
	* 根据已领取人数反格式化
	**/
	public void setRecipients$(String strValue){
		if(Utils.empty(strValue)){
			this.recipients=null;
			return;
		}
	
	
	 	this.recipients=Utils.parseInteger(strValue);
	 
	}
	
	/**
	* 已领取人数       
	**/
	public void setRecipients(Integer recipients){
		this.recipients = recipients;
		
		this.setSeted(F.recipients);
		
	}
	
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 	
 	
	
	
	/*******************************唯一标识**********************************/	
	/**
	* 唯一标识       
	**/
	public String getUnique(){
		
		if(this.unique!=null){
			return this.unique;
		}
		
		return this.unique;
	}
	/**
	* 获取唯一标识格式化(toString)
	**/
	public String getUnique$(){
		String strValue="";
	
	
		 strValue=Utils.string(this.getUnique());
	 
	 	 return strValue;
	}
	/**
	* 根据唯一标识反格式化
	**/
	public void setUnique$(String strValue){
		if(Utils.empty(strValue)){
			this.unique=null;
			return;
		}
	
	
	 	this.unique=strValue;
	 
	}
	
	/**
	* 唯一标识       
	**/
	public void setUnique(String unique){
		this.unique = unique;
		
		this.setSeted(F.unique);
		
	}
	
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 	
 	
	
	
	/*******************************修改时间**********************************/	
	/**
	* 修改时间 [非空]      
	**/
	public Date getUpdateTime(){
		
		if(this.updateTime!=null){
			return this.updateTime;
		}
		
		return this.updateTime;
	}
	/**
	* 获取修改时间格式化(toString)
	**/
	public String getUpdateTime$(){
		String strValue="";
	
	
	 	
		 strValue=Utils.string(Utils.date(this.getUpdateTime(),"yyyy-MM-dd HH:mm:ss"));
		
	 
	 	 return strValue;
	}
	/**
	* 根据修改时间反格式化
	**/
	public void setUpdateTime$(String strValue){
		if(Utils.empty(strValue)){
			this.updateTime=null;
			return;
		}
	
	
	 	this.updateTime=Utils.date(strValue,"yyyy-MM-dd HH:mm:ss");
	 
	}
	
	/**
	* 修改时间 [非空]      
	**/
	public void setUpdateTime(Date updateTime){
		this.updateTime = updateTime;
		
		this.setSeted(F.updateTime);
		
	}
	
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 	
 	
	
	
	/*******************************发放时间**********************************/	
	/**
	* 发放时间 [非空]      
	**/
	public Date getAddTime(){
		
		if(this.addTime!=null){
			return this.addTime;
		}
		
		return this.addTime;
	}
	/**
	* 获取发放时间格式化(toString)
	**/
	public String getAddTime$(){
		String strValue="";
	
	
	 	
		 strValue=Utils.string(Utils.date(this.getAddTime(),"yyyy-MM-dd HH:mm:ss"));
		
	 
	 	 return strValue;
	}
	/**
	* 根据发放时间反格式化
	**/
	public void setAddTime$(String strValue){
		if(Utils.empty(strValue)){
			this.addTime=null;
			return;
		}
	
	
	 	this.addTime=Utils.date(strValue,"yyyy-MM-dd HH:mm:ss");
	 
	}
	
	/**
	* 发放时间 [非空]      
	**/
	public void setAddTime(Date addTime){
		this.addTime = addTime;
		
		this.setSeted(F.addTime);
		
	}
	
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 	
 	
	
	
	/*******************************状态**********************************/	
	/**
	* 状态 [非空]   1:有效中 0:已失效    
	**/
	public Short getStatus(){
		
		if(this.status!=null){
			return this.status;
		}
		
		return this.status;
	}
	/**
	* 获取状态格式化(toString)
	**/
	public String getStatus$(){
		String strValue="";
	
	
		
			
		 if(Utils.equals(Utils.string(this.getStatus()),"1"))
			strValue=Utils.string("有效中");		 
			
		 if(Utils.equals(Utils.string(this.getStatus()),"0"))
			strValue=Utils.string("已失效");		 
			
		
	 
	 	 return strValue;
	}
	/**
	* 根据状态反格式化
	**/
	public void setStatus$(String strValue){
		if(Utils.empty(strValue)){
			this.status=null;
			return;
		}
	
	
		
			
		 if(Utils.equals(strValue,"有效中"))
		 	this.status=Utils.parseShort("1");
			
		 if(Utils.equals(strValue,"已失效"))
		 	this.status=Utils.parseShort("0");
			
		
	 
	}
	
	/**
	* 状态 [非空]   1:有效中 0:已失效    
	**/
	public void setStatus(Short status){
		this.status = status;
		
		this.setSeted(F.status);
		
	}
	
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 	
 	
	
	
	
	/************LAZY3Q_DEFINE_CODE************/
	/************LAZY3Q_DEFINE_CODE************/	
	
	
	/**
	 * 触发器
	 */
	public static void on(Trigger.Index index,final Notify.Listener listener,Trigger.Type... types){
		Notify.on(RedPacket.class, index, listener, types);
	}
	public static void on(final Notify.Listener listener,String type){
		Notify.on(RedPacket.class, listener, type);
	}
	/**
	 * 当修改字段时
	 * @param filedName
	 * @param listener
	 */
	public static void on(String filedName,final Notify.Listener listener){
		Notify.on(RedPacket.class, listener, filedName);
	}
	/**
	 * 当修改字段为某值时
	 * @param filedName
	 * @param value
	 * @param listener
	 */
	public static void on(String filedName,Object value,final Notify.Listener listener){
		if(value==null)return;
		Notify.on(RedPacket.class, listener, filedName+"."+Utils.md5(""+value));
	}
	public void notify(String type){
		Trigger.on(RedPacket.class,type, this);
	}
	
	
	/**
	 * 用来获取当有字段关联对象时的获取方式,调用如${RedPacket.obj.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${RedPacket.$filedName}获取关联对象
	 */
	public Map getObj(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return RedPacket.class.getMethod("get$"+Utils.forMat(key.toString())).invoke(RedPacket.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 用来获取某字段格式化的获取方式,调用如${RedPacket.fmt.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${RedPacket.filedName$}获取某字段格式化
	 */
	public Map getFmt(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return RedPacket.class.getMethod("get"+Utils.ForMat(key.toString()+"$")).invoke(RedPacket.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 获取查询参数链式串
	 * @return
	 */
	public static @Deprecated M where(){ return new M(0); }
	public static @Deprecated M m(){ return new M(0); }
	public static M where = new M(0,true);
	public static @database(DatabaseNames.distribute_sys) class M extends IbatisMap{
		int type = 0; 
		M linked = null;
		Boolean proxy = false;
		public M set = null;
		public M(int type){
			this.type = type;
			if(this.type==0){
				set = new M(1,true);
				set.linked = this;
			}
		};
		public M(int type,Boolean proxy){
			this.type = type;
			this.proxy=proxy;
		};
		public M proxy(){
			M m = new M(this.type);//当前的对像
			if(this.type==0){
				m.set = new M(1,true);//set对象
				m.set.linked = m;
			}else{
				m.linked=this.linked;
				this.linked.linked=m;
			}
			return m;
		}
		public @Deprecated M set(){			
			M m = this;
			m.linked=new M(1);
			m.linked.linked=m;
			return m.linked;
		};
		
		public M on(IbatisMap value,C column,String joinColumn){if(proxy)return proxy().on(value,column,joinColumn);this.put(value.getClass().getDeclaringClass().getSimpleName(), value);value.put("on", column.toString());value.put("to", joinColumn);return this;};
		
		
			
		
		/** 编号 [非空]       **/
		public M id(Object id){if(proxy)return proxy().id(id);  this.put("id", id);return this;};
	 	/** and id is null */
 		public M idNull(){if(proxy)return proxy().idNull();if(this.get("idNot")==null)this.put("idNot", "");this.put("id", null);return this;};
 		/** not .... */
 		public M idNot(){if(proxy)return proxy().idNot();this.put("idNot", "not");return this;};
 		public M idNotNull(){if(proxy)return proxy().idNotNull();this.put("idNot", "not");this.put("id", null);return this;};
 		public M idNot(Object id){if(proxy)return proxy().idNot(id);this.put("idNot", "not");this.put("id", id);return this;};
	 		
		/** and id <= ? */
		public M idMin(Object min){if(proxy)return proxy().idMin(min);this.put("idMin", min);return this;};
		/** and id >= ? */
		public M idMax(Object max){if(proxy)return proxy().idMax(max);this.put("idMax", max);return this;};
			
			
		public M idIn(String ids){
			if(proxy)return proxy().idIn(ids);  this.put("idIn", ids);return this;
		};	
 			
		
			
	 	
			
		public M merchant$on(Merchant.M value){if(proxy)return proxy().merchant$on(value);this.put("Merchant", value);value.put("on", "merchant");return this;};
 				
 			
		
		/** 品牌信息 [非空] [Merchant]      **/
		public M merchant(Object merchant){if(proxy)return proxy().merchant(merchant);  this.put("merchant", merchant);return this;};
	 	/** and merchant is null */
 		public M merchantNull(){if(proxy)return proxy().merchantNull();if(this.get("merchantNot")==null)this.put("merchantNot", "");this.put("merchant", null);return this;};
 		/** not .... */
 		public M merchantNot(){if(proxy)return proxy().merchantNot();this.put("merchantNot", "not");return this;};
 		public M merchantNotNull(){if(proxy)return proxy().merchantNotNull();this.put("merchantNot", "not");this.put("merchant", null);return this;};
 		public M merchantNot(Object merchant){if(proxy)return proxy().merchantNot(merchant);this.put("merchantNot", "not");this.put("merchant", merchant);return this;};
	 		
			
		public M merchantIn(String ids){
			if(proxy)return proxy().merchantIn(ids);  this.put("merchantIn", ids);return this;
		};	
 			
		
			
	 	
			
		
		/** 用户编号 [非空]       **/
		public M uid(Object uid){if(proxy)return proxy().uid(uid);  this.put("uid", uid);return this;};
	 	/** and uid is null */
 		public M uidNull(){if(proxy)return proxy().uidNull();if(this.get("uidNot")==null)this.put("uidNot", "");this.put("uid", null);return this;};
 		/** not .... */
 		public M uidNot(){if(proxy)return proxy().uidNot();this.put("uidNot", "not");return this;};
 		public M uidNotNull(){if(proxy)return proxy().uidNotNull();this.put("uidNot", "not");this.put("uid", null);return this;};
 		public M uidNot(Object uid){if(proxy)return proxy().uidNot(uid);this.put("uidNot", "not");this.put("uid", uid);return this;};
	 		
		/** and uid <= ? */
		public M uidMin(Object min){if(proxy)return proxy().uidMin(min);this.put("uidMin", min);return this;};
		/** and uid >= ? */
		public M uidMax(Object max){if(proxy)return proxy().uidMax(max);this.put("uidMax", max);return this;};
			
			
		public M uidIn(String ids){
			if(proxy)return proxy().uidIn(ids);  this.put("uidIn", ids);return this;
		};	
 			
		
			
	 	
			
		public M redEnveloper$on(Member.M value){if(proxy)return proxy().redEnveloper$on(value);this.put("RedEnveloper", value);value.put("on", "red_enveloper");return this;};
 				
 			
		
		/** 发红包人 [非空] [Member]      **/
		public M redEnveloper(Object redEnveloper){if(proxy)return proxy().redEnveloper(redEnveloper);  this.put("redEnveloper", redEnveloper);return this;};
	 	/** and red_enveloper is null */
 		public M redEnveloperNull(){if(proxy)return proxy().redEnveloperNull();if(this.get("redEnveloperNot")==null)this.put("redEnveloperNot", "");this.put("redEnveloper", null);return this;};
 		/** not .... */
 		public M redEnveloperNot(){if(proxy)return proxy().redEnveloperNot();this.put("redEnveloperNot", "not");return this;};
 		public M redEnveloperNotNull(){if(proxy)return proxy().redEnveloperNotNull();this.put("redEnveloperNot", "not");this.put("redEnveloper", null);return this;};
 		public M redEnveloperNot(Object redEnveloper){if(proxy)return proxy().redEnveloperNot(redEnveloper);this.put("redEnveloperNot", "not");this.put("redEnveloper", redEnveloper);return this;};
	 		
			
		public M redEnveloperIn(String ids){
			if(proxy)return proxy().redEnveloperIn(ids);  this.put("redEnveloperIn", ids);return this;
		};	
 			
		
			
	 	
			
		
		/** 红包数量 [非空]       **/
		public M quantity(Object quantity){if(proxy)return proxy().quantity(quantity);  this.put("quantity", quantity);return this;};
	 	/** and quantity is null */
 		public M quantityNull(){if(proxy)return proxy().quantityNull();if(this.get("quantityNot")==null)this.put("quantityNot", "");this.put("quantity", null);return this;};
 		/** not .... */
 		public M quantityNot(){if(proxy)return proxy().quantityNot();this.put("quantityNot", "not");return this;};
 		public M quantityNotNull(){if(proxy)return proxy().quantityNotNull();this.put("quantityNot", "not");this.put("quantity", null);return this;};
 		public M quantityNot(Object quantity){if(proxy)return proxy().quantityNot(quantity);this.put("quantityNot", "not");this.put("quantity", quantity);return this;};
	 		
		/** and quantity <= ? */
		public M quantityMin(Object min){if(proxy)return proxy().quantityMin(min);this.put("quantityMin", min);return this;};
		/** and quantity >= ? */
		public M quantityMax(Object max){if(proxy)return proxy().quantityMax(max);this.put("quantityMax", max);return this;};
			
			
		public M quantityIn(String ids){
			if(proxy)return proxy().quantityIn(ids);  this.put("quantityIn", ids);return this;
		};	
 			
		
			
	 	
			
		public M product$on(Product.M value){if(proxy)return proxy().product$on(value);this.put("Product", value);value.put("on", "product");return this;};
 				
 			
		
		/** 余额产品 [非空] [Product]      **/
		public M product(Object product){if(proxy)return proxy().product(product);  this.put("product", product);return this;};
	 	/** and product is null */
 		public M productNull(){if(proxy)return proxy().productNull();if(this.get("productNot")==null)this.put("productNot", "");this.put("product", null);return this;};
 		/** not .... */
 		public M productNot(){if(proxy)return proxy().productNot();this.put("productNot", "not");return this;};
 		public M productNotNull(){if(proxy)return proxy().productNotNull();this.put("productNot", "not");this.put("product", null);return this;};
 		public M productNot(Object product){if(proxy)return proxy().productNot(product);this.put("productNot", "not");this.put("product", product);return this;};
	 		
			
		public M productIn(String ids){
			if(proxy)return proxy().productIn(ids);  this.put("productIn", ids);return this;
		};	
 			
		
			
	 	
			
		
		/** 红包类型 [非空]   1:单人红包 2:多人红包     **/
		public M types(Object types){if(proxy)return proxy().types(types);  this.put("types", types);return this;};
	 	/** and types is null */
 		public M typesNull(){if(proxy)return proxy().typesNull();if(this.get("typesNot")==null)this.put("typesNot", "");this.put("types", null);return this;};
 		/** not .... */
 		public M typesNot(){if(proxy)return proxy().typesNot();this.put("typesNot", "not");return this;};
 		public M typesNotNull(){if(proxy)return proxy().typesNotNull();this.put("typesNot", "not");this.put("types", null);return this;};
 		public M typesNot(Object types){if(proxy)return proxy().typesNot(types);this.put("typesNot", "not");this.put("types", types);return this;};
	 		
			
		public M typesIn(String ids){
			if(proxy)return proxy().typesIn(ids);  this.put("typesIn", ids);return this;
		};	
 			
		
			
	 	
			
		
		/** 默认有效期 [非空]       **/
		public M validity(Object validity){if(proxy)return proxy().validity(validity);  this.put("validity", validity);return this;};
	 	/** and validity is null */
 		public M validityNull(){if(proxy)return proxy().validityNull();if(this.get("validityNot")==null)this.put("validityNot", "");this.put("validity", null);return this;};
 		/** not .... */
 		public M validityNot(){if(proxy)return proxy().validityNot();this.put("validityNot", "not");return this;};
 		public M validityNotNull(){if(proxy)return proxy().validityNotNull();this.put("validityNot", "not");this.put("validity", null);return this;};
 		public M validityNot(Object validity){if(proxy)return proxy().validityNot(validity);this.put("validityNot", "not");this.put("validity", validity);return this;};
	 		
 		/** and validity >= ? */
 		public M validityStart(Object start){if(proxy)return proxy().validityStart(start);this.put("validityStart", start);return this;};			
 		/** and validity <= ? */
 		public M validityEnd(Object end){if(proxy)return proxy().validityEnd(end);this.put("validityEnd", end);return this;};
			
			
		
			
	 	
			
		
		/** 已领取人数        **/
		public M recipients(Object recipients){if(proxy)return proxy().recipients(recipients);  this.put("recipients", recipients);return this;};
	 	/** and recipients is null */
 		public M recipientsNull(){if(proxy)return proxy().recipientsNull();if(this.get("recipientsNot")==null)this.put("recipientsNot", "");this.put("recipients", null);return this;};
 		/** not .... */
 		public M recipientsNot(){if(proxy)return proxy().recipientsNot();this.put("recipientsNot", "not");return this;};
 		public M recipientsNotNull(){if(proxy)return proxy().recipientsNotNull();this.put("recipientsNot", "not");this.put("recipients", null);return this;};
 		public M recipientsNot(Object recipients){if(proxy)return proxy().recipientsNot(recipients);this.put("recipientsNot", "not");this.put("recipients", recipients);return this;};
	 		
		/** and recipients <= ? */
		public M recipientsMin(Object min){if(proxy)return proxy().recipientsMin(min);this.put("recipientsMin", min);return this;};
		/** and recipients >= ? */
		public M recipientsMax(Object max){if(proxy)return proxy().recipientsMax(max);this.put("recipientsMax", max);return this;};
			
			
		public M recipientsIn(String ids){
			if(proxy)return proxy().recipientsIn(ids);  this.put("recipientsIn", ids);return this;
		};	
 			
		
			
	 	
			
		
		/** 唯一标识        **/
		public M unique(Object unique){if(proxy)return proxy().unique(unique);  this.put("unique", unique);return this;};
	 	/** and unique is null */
 		public M uniqueNull(){if(proxy)return proxy().uniqueNull();if(this.get("uniqueNot")==null)this.put("uniqueNot", "");this.put("unique", null);return this;};
 		/** not .... */
 		public M uniqueNot(){if(proxy)return proxy().uniqueNot();this.put("uniqueNot", "not");return this;};
 		public M uniqueNotNull(){if(proxy)return proxy().uniqueNotNull();this.put("uniqueNot", "not");this.put("unique", null);return this;};
 		public M uniqueNot(Object unique){if(proxy)return proxy().uniqueNot(unique);this.put("uniqueNot", "not");this.put("unique", unique);return this;};
	 		
			
		
			
	 	
			
		
		/** 修改时间 [非空]       **/
		public M updateTime(Object updateTime){if(proxy)return proxy().updateTime(updateTime);  this.put("updateTime", updateTime);return this;};
	 	/** and update_time is null */
 		public M updateTimeNull(){if(proxy)return proxy().updateTimeNull();if(this.get("updateTimeNot")==null)this.put("updateTimeNot", "");this.put("updateTime", null);return this;};
 		/** not .... */
 		public M updateTimeNot(){if(proxy)return proxy().updateTimeNot();this.put("updateTimeNot", "not");return this;};
 		public M updateTimeNotNull(){if(proxy)return proxy().updateTimeNotNull();this.put("updateTimeNot", "not");this.put("updateTime", null);return this;};
 		public M updateTimeNot(Object updateTime){if(proxy)return proxy().updateTimeNot(updateTime);this.put("updateTimeNot", "not");this.put("updateTime", updateTime);return this;};
	 		
 		/** and update_time >= ? */
 		public M updateTimeStart(Object start){if(proxy)return proxy().updateTimeStart(start);this.put("updateTimeStart", start);return this;};			
 		/** and update_time <= ? */
 		public M updateTimeEnd(Object end){if(proxy)return proxy().updateTimeEnd(end);this.put("updateTimeEnd", end);return this;};
			
			
		
			
	 	
			
		
		/** 发放时间 [非空]       **/
		public M addTime(Object addTime){if(proxy)return proxy().addTime(addTime);  this.put("addTime", addTime);return this;};
	 	/** and add_time is null */
 		public M addTimeNull(){if(proxy)return proxy().addTimeNull();if(this.get("addTimeNot")==null)this.put("addTimeNot", "");this.put("addTime", null);return this;};
 		/** not .... */
 		public M addTimeNot(){if(proxy)return proxy().addTimeNot();this.put("addTimeNot", "not");return this;};
 		public M addTimeNotNull(){if(proxy)return proxy().addTimeNotNull();this.put("addTimeNot", "not");this.put("addTime", null);return this;};
 		public M addTimeNot(Object addTime){if(proxy)return proxy().addTimeNot(addTime);this.put("addTimeNot", "not");this.put("addTime", addTime);return this;};
	 		
 		/** and add_time >= ? */
 		public M addTimeStart(Object start){if(proxy)return proxy().addTimeStart(start);this.put("addTimeStart", start);return this;};			
 		/** and add_time <= ? */
 		public M addTimeEnd(Object end){if(proxy)return proxy().addTimeEnd(end);this.put("addTimeEnd", end);return this;};
			
			
		
			
	 	
			
		
		/** 状态 [非空]   1:有效中 0:已失效     **/
		public M status(Object status){if(proxy)return proxy().status(status);  this.put("status", status);return this;};
	 	/** and status is null */
 		public M statusNull(){if(proxy)return proxy().statusNull();if(this.get("statusNot")==null)this.put("statusNot", "");this.put("status", null);return this;};
 		/** not .... */
 		public M statusNot(){if(proxy)return proxy().statusNot();this.put("statusNot", "not");return this;};
 		public M statusNotNull(){if(proxy)return proxy().statusNotNull();this.put("statusNot", "not");this.put("status", null);return this;};
 		public M statusNot(Object status){if(proxy)return proxy().statusNot(status);this.put("statusNot", "not");this.put("status", status);return this;};
	 		
			
		public M statusIn(String ids){
			if(proxy)return proxy().statusIn(ids);  this.put("statusIn", ids);return this;
		};	
 			
		
			
	 	
	 	public M add(String key, Object value) {if(proxy)return proxy().add(key,value);this.put(key, value);return this;}
	 	public M add(F key, Object value) {if(proxy)return proxy().add(key,value);this.put(key.toString(), value);return this;}
	 	
	 	public M desc(C key) {if(proxy)return proxy().desc(key);this.put("desc", key.column);return this;}
	 	public M asc(C key) {if(proxy)return proxy().asc(key);this.put("asc", key.column);return this;}
	 	public M desc(String sql) {if(proxy)return proxy().desc(sql);this.put("desc", sql);return this;}
	 	public M asc(String sql) {if(proxy)return proxy().asc(sql);this.put("asc", sql);return this;}
	 	public M definex(String sql) {if(proxy)return proxy().definex(sql);this.put("definex", sql);return this;}
	 	
	 	/** 获取所有派发红包 **/
		public @api List<RedPacket> list(Integer size){			
			return getRedPacketList(this,size);
		}
		/** 获取派发红包分页 **/
		public @api Page<RedPacket> page(Integer page,Integer size){			
			return getRedPacketPage(page, size , this);
		}
		/** 根据查询条件取派发红包 **/
		public @api RedPacket get(){			
			return getRedPacket(this);
		}
		/** 获取派发红包数 **/
		public @api Long count(){			
			return getRedPacketCount(this);
		}
		/** 获取派发红包表达式 **/
		public @api <T> T eval(String strEval){			
			return getRedPacketEval(strEval,this);
		}
		
		/** 获取派发红包统计 **/
		public @api List<Map> stats(C sumKey,C groupKey,int dateType){			
			return getRedPacketStats(this,sumKey,groupKey,dateType);
		}
		/** 获取派发红包统计 **/
		public @api List<Map> stats(C sumKey,C groupKey){			
			return getRedPacketStats(this,sumKey,groupKey,-1);
		}
		
		/** 根据条件更新 **/
		public @api int update(){			
			M where = null;
			M set = null;
			if(this.type==0){
				if(this.linked==null)throw new RuntimeException("未发set");
				where = this;
				set = this.linked;
			}else{
				if(this.linked==null)throw new RuntimeException("未发where条件");
				set = this;
				where = this.linked;
			}
			return updateRedPacket(set,where);
		}
		/** 根据条件删除 **/
		public @api void delete(){			
			deleteRedPacket(this);
		}
	}
	
	public static class Param extends M{
		public Param(int type) {
			super(type);
		}
		public Param(int type, Boolean proxy) {
			super(type, proxy);
		}
	}
	
	/** 对象的字段描述 **/
	public static class F{
		
			
		/** 编号 [非空]       **/
		public final static @type(Long.class)  String id="id";
	 			
			
	 	
			
		/** 品牌信息 [非空] [Merchant]      **/
		public final static @type(Long.class)  String merchant="merchant";
	 			
			
	 	
			
		/** 用户编号 [非空]       **/
		public final static @type(Long.class)  String uid="uid";
	 			
			
	 	
			
		/** 发红包人 [非空] [Member]      **/
		public final static @type(Long.class)  String redEnveloper="redEnveloper";
	 			
			
	 	
			
		/** 红包数量 [非空]       **/
		public final static @type(Integer.class)  String quantity="quantity";
	 			
		/** and quantity >= ? */
		public final static @type(Integer.class) String quantityMin="quantityMin";
		/** and quantity <= ? */
		public final static @type(Integer.class) String quantityMax="quantityMax";
				
			
	 	
			
		/** 余额产品 [非空] [Product]      **/
		public final static @type(Long.class)  String product="product";
	 			
			
	 	
			
		/** 红包类型 [非空]   1:单人红包 2:多人红包     **/
		public final static @type(Short.class)  String types="types";
	 			
			
	 	
			
		/** 默认有效期 [非空]       **/
		public final static @type(Date.class)  String validity="validity";
	 			
	 	/** and validity >= ? */
 		public final static @type(Date.class) String validityStart="validityStart";
 		/** and validity <= ? */
 		public final static @type(Date.class) String validityEnd="validityEnd";
				
			
	 	
			
		/** 已领取人数        **/
		public final static @type(Integer.class)  String recipients="recipients";
	 			
		/** and recipients >= ? */
		public final static @type(Integer.class) String recipientsMin="recipientsMin";
		/** and recipients <= ? */
		public final static @type(Integer.class) String recipientsMax="recipientsMax";
				
			
	 	
			
		/** 唯一标识        **/
		public final static @type(String.class)  String unique="unique";
	 			
			
	 	
			
		/** 修改时间 [非空]       **/
		public final static @type(Date.class)  String updateTime="updateTime";
	 			
	 	/** and update_time >= ? */
 		public final static @type(Date.class) String updateTimeStart="updateTimeStart";
 		/** and update_time <= ? */
 		public final static @type(Date.class) String updateTimeEnd="updateTimeEnd";
				
			
	 	
			
		/** 发放时间 [非空]       **/
		public final static @type(Date.class)  String addTime="addTime";
	 			
	 	/** and add_time >= ? */
 		public final static @type(Date.class) String addTimeStart="addTimeStart";
 		/** and add_time <= ? */
 		public final static @type(Date.class) String addTimeEnd="addTimeEnd";
				
			
	 	
			
		/** 状态 [非空]   1:有效中 0:已失效     **/
		public final static @type(Short.class)  String status="status";
	 			
			
	 	
	 	public static String get(String name){
			try {
				Field field = F.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	
	
	
	/** 对象的数据库字段描述 **/
	public static enum C{
		
		id("id"),
		merchant("merchant"),
		uid("uid"),
		redEnveloper("red_enveloper"),
		quantity("quantity"),
		product("product"),
		types("types"),
		validity("validity"),
		recipients("recipients"),
		unique("unique"),
		updateTime("update_time"),
		addTime("add_time"),
		status("status"),
		count("count");
		String column;
		C(String column){
			this.column = column;
		}
		public String toString(){
			return this.column;
		}
		public static String get(String name){
			try {
				Field field = C.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	
	
	
	
	/**
	* 获取派发红包数据
	**/
	public static Object getData(Object param){
		if(param==null)
			return null;
		Object value = null;
		if(param.getClass()==Long.class)
			value = RedPacket.get((Long)param);
		else if(param instanceof java.util.Map){
			java.util.Map params = (Map) param;
			if(params.get("size")==null)
				value = RedPacket.getRedPacket(params);
			else
				value = RedPacket.getRedPacketList(params, (Integer) params.get("size"));
		}else if(param.getClass()==Long.class )
			value =  RedPacket.where().id(param).get();
		else if(!Utils.empty(param.toString()))
			value = RedPacket.get(Long.valueOf(param.toString()));
		return value;
	}
	
	/**对象转json**/
	public Map toJSON(){
		return toJSON(false);
	}
	public Map toJSON(boolean simple){
		Map map = new HashMap();
		map.put("id",this.getId());
	
		Utils.fms(map,simple?"":"id",this.getId(),this.getId$());
 		
	
		Utils.fms(map,simple?"":"merchant",this.getMerchant(),this.getMerchant$());
 		
	
		Utils.fms(map,simple?"":"uid",this.getUid(),this.getUid$());
 		
	
		Utils.fms(map,simple?"enveloper":"redEnveloper",this.getRedEnveloper(),this.getRedEnveloper$());
 		
	
		Utils.fms(map,simple?"":"quantity",this.getQuantity(),this.getQuantity$());
 		
	
		Utils.fms(map,simple?"":"product",this.getProduct(),this.getProduct$());
 		
	
		Utils.fms(map,simple?"":"types",this.getTypes(),this.getTypes$());
 		
	
		Utils.fms(map,simple?"":"validity",this.getValidity(),this.getValidity$());
 		
	
		Utils.fms(map,simple?"":"recipients",this.getRecipients(),this.getRecipients$());
 		
	
		Utils.fms(map,simple?"":"unique",this.getUnique(),this.getUnique$());
 		
	
		Utils.fms(map,simple?"time":"updateTime",this.getUpdateTime(),this.getUpdateTime$());
 		
	
		Utils.fms(map,simple?"time":"addTime",this.getAddTime(),this.getAddTime$());
 		
	
		Utils.fms(map,simple?"":"status",this.getStatus(),this.getStatus$());
 		
	
		if(this.suffix!=null)map.put("suffix", this.suffix);
		
		/************LAZY3Q_DEFINE_TOJSON************/
		/************LAZY3Q_DEFINE_TOJSON************/
		return map;
	}
	/**对象转map**/
	public Map toMap(){
		Map map = new HashMap();
	
		map.put("id",this.getId());
 		
	
		map.put("merchant",this.getMerchant());
 		
	
		map.put("uid",this.getUid());
 		
	
		map.put("redEnveloper",this.getRedEnveloper());
 		
	
		map.put("quantity",this.getQuantity());
 		
	
		map.put("product",this.getProduct());
 		
	
		map.put("types",this.getTypes());
 		
	
		map.put("validity",this.getValidity());
 		
	
		map.put("recipients",this.getRecipients());
 		
	
		map.put("unique",this.getUnique());
 		
	
		map.put("updateTime",this.getUpdateTime());
 		
	
		map.put("addTime",this.getAddTime());
 		
	
		map.put("status",this.getStatus());
 		
	
		map.put("suffix", this.suffix);
		
		/************LAZY3Q_DEFINE_TOMAP************/
		/************LAZY3Q_DEFINE_TOMAP************/
		return map;
	}
	/**map转对象**/
	public static RedPacket fromMap(Map map){
		RedPacket redPacket = new RedPacket();
	
		redPacket.id = Utils.parseLong(map.get("id"));
 		
	
		redPacket.merchant = Utils.parseLong(map.get("merchant"));
 		
	
	
		redPacket.redEnveloper = Utils.parseLong(map.get("redEnveloper"));
 		
	
		redPacket.quantity = Utils.parseInteger(map.get("quantity"));
 		
	
		redPacket.product = Utils.parseLong(map.get("product"));
 		
	
		redPacket.types = Utils.parseShort(map.get("types"));
 		
	
		redPacket.validity = Utils.parseDate(map.get("validity"));
 		
	
		redPacket.recipients = Utils.parseInteger(map.get("recipients"));
 		
	
		redPacket.unique = Utils.parseString(map.get("unique"));
 		
	
		redPacket.updateTime = Utils.parseDate(map.get("updateTime"));
 		
	
		redPacket.addTime = Utils.parseDate(map.get("addTime"));
 		
	
		redPacket.status = Utils.parseShort(map.get("status"));
 		
	
		return redPacket;
	}
	
	
	/**字段设置标记队列**/
	private Map<String,Boolean> seted=new HashMap();
	public Boolean getSeted(String key){
		return seted.get(key);
	}
	public void setSeted(String key){
		seted.put(key,true);
	}
	/**同步未set的字段**/
	public void mergeSet(RedPacket old){
		Field[] fields = this.getClass().getDeclaredFields();
		try {
			for(Field field:fields){
				String key = field.getName();
				if(seted.get(key)==null && field.getAnnotation(column.class)!=null){
					field.setAccessible(true);
					field.set(this, field.get(old));					
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
		
	/**自定义变量存储**/
	private Map values=new HashMap();
	public Map getValues(){
		return values;
	}
	public void setValues(String name,Object value){
		values.put(name,value);
	}
	
	/**分表时的表名后缀**/
	private String suffix;
	public String getSuffix() {
		return suffix;
	}
	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}
	
	
	/**获取数据库名称**/
	public static String getDataBaseName(){
		return Utils.config("spring.datasource.distribute_sys.name");
	}
	
	
	public static String getIcon(){
		return "/images/icons/20088256421529677805.png";
	}
	public static String getIconfont(){
		return "icon-youjian1";
	}
	public static enum ACT{
		列表,添加,修改,详情
	};
	public static String getUrl(ACT act,RedPacket.M params){
		if(params==null)params=new RedPacket.M(0);
		params.remove("joins");
		params.remove("definexs");
		params.remove("distinct");
		String strUrl = "/admin/products/redpacket.edit.html?";
		if(params.get("id")!=null){
			strUrl+="&id="+Utils.encode(""+params.get("id"),Utils.UTF8);
		}
		if(act==ACT.列表){
			strUrl = "/admin/products/redpacket.html?1=1";
		
		}else if(act==ACT.添加){
			strUrl+="&edittype=insert";
		
		
		}else if(act==ACT.修改){
			strUrl+="&edittype=update";
		
		}else if(act==ACT.详情){
			strUrl+="&edittype=detail";
		
		}		
		if(params!=null){
			for(Object key:params.keySet()){
				strUrl+="&"+key+"="+Utils.encode(""+params.get(key),Utils.UTF8)+"";
			}
		}
		return strUrl;
	}
	public String getDetailUrl(){
		return this.getUrl(ACT.详情, where.id(this.getId()));
	}
	
	/**
	* 转跳到当前地址
	**/
	public static Protocol redirect(RedPacket.ACT act,RedPacket.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_REDIRECT");
		protocol.set("url",RedPacket.getUrl(act, params));
		return protocol;
	}
	/**
	* 打开一个新的tab页面
	**/
	public static Protocol href(RedPacket.ACT act,RedPacket.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_HREF");
		protocol.set("url",RedPacket.getUrl(act, params));
		protocol.set("title",act.name());
		return protocol;
	}
	/**
	* 显示一个消息框，并且关闭当前的对话框
	**/
	public static Protocol message(String message){
		Protocol protocol = Protocol.create(true,null,"ACT_MESSAGE");
		protocol.set("message",message);
		return protocol;
	}
	
	
	static com.distribute.framework.dao.IRedPacketDao getRedPacketDao(){
		return Utils.getBean("redPacketDao");
	};
	
}